<?php
date_default_timezone_set('Asia/Shanghai');//时区配置
$conn=mysql_connect("localhost","root","gsda1.mysql1");
mysql_select_db("new_gsdai", $conn);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);

$sql = "SELECT t1.id,borrow_id,repay_account,t1.user_id FROM ych_borrow_collection AS t1 LEFT JOIN 
		ych_borrow AS t2 ON t1.borrow_id=t2.id WHERE repay_time>1377273600 AND repay_time<1377360000 AND t2.ftype=4";

$result = db_fetch_arrays($sql, $conn);
foreach ($result as $key => $value){
	$id 				= $value['id'];
	$borrow_id 			= $value['borrow_id'];
	$repay_account 		= $value['repay_account'];
	$user_id 			= $value['user_id'];
	$sql = "update ych_account set total=total-{$repay_account},use_money=use_money+{$repay_account} where user_id={$user_id}";
	$query = mysql_query($sql, $conn);
	if(!$query){
		echo $sql;
		exit;
	}
}



function db_fetch_arrays($sql, $conn) 	{
	$result = mysql_query($sql, $conn);
	$i = 0;
	$_res = array();
	while($res = mysql_fetch_array($result,MYSQL_ASSOC)) {
		foreach ($res as $key => $value){
			$_res[$i][$key] = $value;//直接转义
		}
		$i++;
	}
	return $_res;
}

function db_fetch_array($sql,$conn) {
		$result = mysql_query($sql, $conn);
		$res = mysql_fetch_array($result,MYSQL_ASSOC);
		$_res = "";
		if (is_array($res)){
			foreach ($res as $key => $value){
				$_res[$key] =$value;
			}
		}
		$query = $_res;
		return $query;
}